 function formatterDateTime() {
  var date=new Date()
  var month=date.getMonth() + 1
        var datetime = date.getFullYear()
                + ""// "年"
                + (month >= 10 ? month : "0"+ month)
                + ""// "月"
                + (date.getDate() < 10 ? "0" + date.getDate() : date
                        .getDate())
                + ""
                + (date.getHours() < 10 ? "0" + date.getHours() : date
                        .getHours())
                + ""
                + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
                        .getMinutes())
                + ""
                + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
                        .getSeconds());
        return datetime;
}
// 获取文件类名
function extname(filename){
	var arr = filename.split('.');
	return ((arr.length>1 && arr[0]!=='')? arr[arr.length-1] : '')
}

// 图片类
function sexyAjax(){
	$.ajax({
	    type: 'post',
	    url: 'http://route.showapi.com/1208-1',
	    dataType: 'json',
	    data: {
	        "showapi_timestamp": formatterDateTime(),
	        "showapi_appid": '44966', //这里需要改成自己的appid
	        "showapi_sign": '6cae83dfd63e4c52af67dd9fe32dbe1c',  //这里需要改成自己的应用的密钥secret
	    },
	
	    error: function(XmlHttpRequest, textStatus, errorThrown) {
	        alert("操作失败!");
	    },
	    success: function(result) {
			var _data = result.showapi_res_body.data;
//			console.log(_data);
			var html="";
			for(var i=0; i<_data.length;i++){
				html +='<a href="#more-'+_data[i].id+'">'+ _data[i].title +'</a>';
			}
			$('.am-titlebar-nav').html(html);
			
		}
	});
}
//图片列表
function defAjax(type,page,callback){
	loadmore('show');
	$.ajax({
	    type: 'post',
	    url: 'http://route.showapi.com/1208-2',
	    dataType: 'json',
	    data: {
	        "showapi_timestamp": formatterDateTime(),
	        "showapi_appid": '44966', //这里需要改成自己的appid
	        "showapi_sign": '6cae83dfd63e4c52af67dd9fe32dbe1c',  //这里需要改成自己的应用的密钥secret
	        "type":type,
	        "page":page,
	        "rows":"10"
	    },
	
	    error: function(XmlHttpRequest, textStatus, errorThrown) {
	        alert("操作失败!");
	    },
	    success: function(result) {
			var _data = result.showapi_res_body.data;
//			console.log(_data);
			var html="";
			if(_data==""){alert("没有了");}
			for(var i=0; i<_data.length;i++){
				html += '<li>'+
						    '<a class="am-gallery-item" href="imgtest.html?num='+_data[i].id+'">'+
						    	'<img src="'+_data[i].imgurl+'" alt="'+_data[i].title+'" data-rel="'+_data[i].imgurl+'"/>'+
						    	'<h3 class="am-gallery-title">'+_data[i].title+'</h3>'+
								'<div class="am-gallery-desc"> image:'+_data[i].imgcount+'</div>'+
						    '</a>'+
						'</li>';
			}
			var defhtml = $('#sexylist').html();
			defhtml += html;
			$('#sexylist').html(defhtml);
			setTimeout(function(){
				loadmore();
			},100)
			if(typeof callback == "function") {
				callback();
			} 
		}
	});
}

function loadmore(shows){
//	console.log(shows);
	if(shows == undefined){
		$(".load_more").hide();
	}else{
		$(".load_more").show();
	}
	
}


// 百思不得姐
function sister(type,page,callback){
	
	loadmore('show');
	
	$.ajax({
    type: 'post',
    url: 'http://route.showapi.com/255-1',
    dataType: 'json',
    data: {
        "showapi_timestamp": formatterDateTime(),
        "showapi_appid": '44966', //这里需要改成自己的appid
        "showapi_sign": '6cae83dfd63e4c52af67dd9fe32dbe1c',  //这里需要改成自己的应用的密钥secret
        "type":type,
        "page":page
    },

    error: function(XmlHttpRequest, textStatus, errorThrown) {
        alert("操作失败!");
    },
    success: function(result) {
//      alert(result.showapi_res_code)
		var _data = result.showapi_res_body.pagebean.contentlist;
//		console.log(_data);
		var html="";
		var count = 0;
		
		if(type==10){
			if(_data==""){alert("没有了");}
			for(var i=0; i<_data.length;i++){
				var imgtype = extname(_data[i].image0);
				if(imgtype==='gif'){
					html += '<li>'+
						    '<div class="am-gallery-item">'+
						    	'<h3 class="am-gallery-title">'+_data[i].text+'</h3>'+
								'<div class="am-gallery-desc"> name:'+_data[i].name+'</div>'+
						    	'<img src="'+_data[i].image0+'" alt="'+_data[i].text+'" data-rel="'+_data[i].image0+'"/>'+
						    '</div>'+
						'</li>';
				}
				
			}
		}else if(type==29){
			if(_data==""){alert("没有了");}
			for(var i=0; i<_data.length;i++){
				html += '<article class="am-comment">'+
						  '<a href="#link-to-user-home">'+
						    '<img src="'+_data[i].profile_image+'" alt="" class="am-comment-avatar" width="48" height="48"/>'+
						  '</a>'+
						  '<div class="am-comment-main">'+
						    '<header class="am-comment-hd">'+
						      '<div class="am-comment-meta">'+
						        '<a href="#link-to-user" class="am-comment-author">'+_data[i].name+'</a>'+
						        '  <time datetime="'+_data[i].create_time+'" title="'+_data[i].create_time+'">'+_data[i].create_time+'</time>'+
						      '</div>'+
						    '</header>'+
						    '<div class="am-comment-bd">'+
						    	_data[i].text +
						    '</div>'+
						  '</div>'+
						'</article>';
			}
		}else if(type==31){
			if(_data==""){
				alert("没有更多内容了");
				var scolltop = $(document).scrollTop();
//				alert(scolltop);
				$('html,body').animate({scrollTop:scolltop-50},600);
			}
			
			for(var i=0; i<_data.length;i++){
				html += '<article class="am-comment">'+
						  '<a href="#link-to-user-home">'+
						    '<img src="'+_data[i].profile_image+'" alt="" class="am-comment-avatar" width="48" height="48"/>'+
						  '</a>'+
						  '<div class="am-comment-main">'+
						    '<header class="am-comment-hd">'+
						      '<div class="am-comment-meta">'+
						        '<a href="#link-to-user" class="am-comment-author">'+_data[i].name+'</a>'+
						        '  <time datetime="'+_data[i].create_time+'" title="'+_data[i].create_time+'">'+_data[i].create_time+'</time>'+
						      '</div>'+
						    '</header>'+
						    '<div class="am-comment-bd" style="position:relative;padding:0;">'+
						    	'<img src="'+_data[i].image3+'" class="voice_img" />'+
						    	'<div class="voicebox">'+
						    		'<audio src="'+_data[i].voice_uri+'" controls="controls"></audio>'+
						    		'<span>'+_data[i].text+'</span>' +
						    	'</div>'+
						    '</div>'+
						  '</div>'+
						'</article>';
			}
		}else if(type==41){
			if(_data==""){alert("没有了");}
//			console.log(_data)
			
			for(var i=0; i<_data.length;i++){
				html += '<article class="am-comment">'+
						  '<a href="#link-to-user-home">'+
						    '<img src="'+_data[i].profile_image+'" alt="" class="am-comment-avatar" width="48" height="48"/>'+
						  '</a>'+
						  '<div class="am-comment-main">'+
						    '<header class="am-comment-hd">'+
						      '<div class="am-comment-meta">'+
						        '<a href="#link-to-user" class="am-comment-author">'+_data[i].name+'</a>'+
						        '  <time datetime="'+_data[i].create_time+'" title="'+_data[i].create_time+'">'+_data[i].create_time+'</time>'+
						      '</div>'+
						    '</header>'+
						    '<div class="am-comment-bd">'+
						    	_data[i].text +
						    	'<div class="video_box">' +
						    	'<video poster="images/111.jpg" id="video'+ count++ +'" src="'+_data[i].video_uri+'" type="video/mp4" controls="controls">'+
								'您的浏览器不支持 video 标签。'+
								'</video>'+
								'</div>'+
								'<div id="img'+ count++ +'"></div>'+
						    '</div>'+
						  '</div>'+
						'</article>';
			}
			
			
		}
		
		var defhtml = $('#sexylist').html();
		defhtml += html;
		$('#sexylist').html(defhtml);
		setTimeout(function(){
			loadmore();
		},100)
		
//		console.log(count)
//		if(count!=0){
//			for(var j=0; j<count; j++) {
//	            (function(val){
//	            	$("#video"+val).on("loadeddata", function (e) {
//		            	alert(e.target.id)
//		                var obj = e.target;
//		                var scale = 0.8;
//		                var canvas = document.createElement("canvas");
//		                canvas.width = obj.videoWidth * scale;
//		                canvas.height = obj.videoHeight * scale;
//		                canvas.getContext('2d').drawImage(obj, 0, 0, canvas.width, canvas.height);
//		                obj.setAttribute("poster", canvas.toDataURL("image/png"));
//		                var img = document.createElement("img");
//					    img.src = canvas.toDataURL("image/png");
//					    img.width = 400;
//					    img.height = 300;
//					    $("#img"+val).appendChild(img);
//					    
//		            })
//	            })(j)
//	        }
//		}
		
		
		if(typeof callback == "function") {
			callback();
		} 
    }
  });

}

// 性感图片
function imgAjax(type,page,num,callback){
	loadmore("show");
	$.ajax({
	    type: 'post',
	    url: 'http://route.showapi.com/819-1',
	    dataType: 'json',
	    data: {
	        "showapi_timestamp": formatterDateTime(),
	        "showapi_appid": '44966', //这里需要改成自己的appid
	        "showapi_sign": '6cae83dfd63e4c52af67dd9fe32dbe1c',  //这里需要改成自己的应用的密钥secret
	        "type":type,
	        "page":page,
	        "num":num
	    },
	
	    error: function(XmlHttpRequest, textStatus, errorThrown) {
	        alert("操作失败!");
	    },
	    success: function(result) {
//	        console.log(result);
//	        music = result.showapi_res_body;
	        var _data = result.showapi_res_body;
	        // 删除对象属性  ret_code
	        delete _data.ret_code;
	        var html="";
			if(_data==""){alert("没有了");}
			for(var i in _data){
//				console.log(i)
				html += '<li>'+
						    '<div class="am-gallery-item">'+
						    	'<h3 class="am-gallery-title">'+_data[i].title+'</h3>'+
						    	'<img src="'+_data[i].thumb+'" alt="'+_data[i].title+'" data-rel="'+_data[i].thumb+'"/>'+
						    '</div>'+
						'</li>';
			}
			var defhtml = $('#sexylist').html();
			defhtml += html;
			$('#sexylist').html(defhtml);
			setTimeout(function(){
				loadmore();
			},100)
			if(typeof callback == "function") {
				callback();
			} 
	    }
	});
	
}

// 笑话大全
function Jokes(url,page,callback){
	
	loadmore('show');
	
	$.ajax({
    type: 'post',
    url: 'http://route.showapi.com/341-'+ url ,
    dataType: 'json',
    data: {
        "showapi_timestamp": formatterDateTime(),
        "showapi_appid": '44966', //这里需要改成自己的appid
        "showapi_sign": '6cae83dfd63e4c52af67dd9fe32dbe1c',  //这里需要改成自己的应用的密钥secret
        "page":page
    },

    error: function(XmlHttpRequest, textStatus, errorThrown) {
        alert("操作失败!");
    },
    success: function(result) {
//      alert(result.showapi_res_code)
		var _data = result.showapi_res_body.contentlist;
//		console.log(_data);
		var html="";
		
		for(var i=0; i<_data.length;i++){
			html += '<article class="am-comment">'+
					  '<div class="am-comment-main">'+
					    '<header class="am-comment-hd">'+
					      '<div class="am-comment-meta">'+
					        '<a href="#link-to-user" class="am-comment-author">'+_data[i].title+'</a>'+
					        '<div class="mt5"><time datetime="'+_data[i].ct+'" title="'+_data[i].ct+'">'+_data[i].ct+'</time></div>'+
					      '</div>'+
					    '</header>'+
					    '<div class="am-comment-bd">'+
					    	(url==1 ? _data[i].text : '<img src="' +_data[i].img +'"/>') +
					    '</div>'+
					  '</div>'+
					'</article>';
		}

		var defhtml = $('#sexylist').html();
		defhtml += html;
		$('#sexylist').html(defhtml);
		setTimeout(function(){
			loadmore();
		},100)
		if(typeof callback == "function") {
			callback();
		} 
    }
  });

}